package com.example.administrator.x2picturetransliteration.Util;

import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.example.administrator.x2picturetransliteration.R;

/**
 * Created by Administrator on 2019/8/5.
 */

public class ToastUtil extends Toast{

    /**
     * Construct an empty Toast object.  You must call {@link #setView} before you
     * can call {@link #show}.
     *
     * @param context The context to use.  Usually your {@link Application}
     *                or {@link Activity} object.
     */

    private Context context;

    public ToastUtil(Context context) {
        super(context);

        this.context = context;
    }

//    new ToastUtil(context).getToast(false,Constants.getConstants().getAbnormal()).show();

    public Toast getToast(boolean judge, CharSequence text){

        Toast mToast = new Toast(context);

        mToast.setGravity(Gravity.CENTER, 0, 0);
        mToast.setDuration(LENGTH_SHORT);

        LayoutInflater inflater = ((Activity)context).getLayoutInflater();
        LinearLayout toastLayout = (LinearLayout)inflater.inflate(R.layout.home_toast, null);

        TextView textView = toastLayout.findViewById(R.id.text);

        textView.setText(text);

        mToast.setView(toastLayout);

        return mToast;
    }

}
